"""
支付相关Schemas
"""
from pydantic import BaseModel
from datetime import datetime
from typing import Optional


class PaymentInfo(BaseModel):
    """支付信息"""
    id: int
    payment_no: str
    order_id: int
    order_no: str
    payment_method: str
    amount: float
    status: str
    third_party_trade_no: Optional[str] = None
    created_at: datetime
    paid_at: Optional[datetime] = None
    expired_at: Optional[datetime] = None
    
    class Config:
        from_attributes = True


class PaymentCreate(BaseModel):
    """创建支付请求"""
    order_id: int
    payment_method: str = "alipay"


class PaymentResponse(BaseModel):
    """支付响应"""
    payment_no: str
    payment_url: str  # 支付URL或二维码URL
    order_no: str
    amount: float
    expired_at: Optional[datetime] = None
    qr_code: Optional[str] = None  # 二维码内容（用于二维码支付）
    payment_type: Optional[str] = None  # 支付类型：qrcode（二维码）或 page（页面）


class RefundInfo(BaseModel):
    """退款信息"""
    id: int
    refund_no: str
    payment_id: int
    order_id: int
    order_no: str
    refund_amount: float
    refund_reason: Optional[str] = None
    status: str
    third_party_refund_no: Optional[str] = None
    created_at: datetime
    refunded_at: Optional[datetime] = None
    
    class Config:
        from_attributes = True


class RefundCreate(BaseModel):
    """创建退款请求"""
    order_id: int
    refund_amount: Optional[float] = None  # 不传则全额退款
    refund_reason: str = "用户申请退款"


class RefundResponse(BaseModel):
    """退款响应"""
    refund_no: str
    order_no: str
    refund_amount: float
    status: str

